home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / earcd / dev / mui / mui37_de.lha / Amiga-E / Examples / Settings.e < prev    next >
Text File  |  1996-08-25  |  6KB  |  209 lines

  1. /*
  2. **  Original C Code written by Stefan Stuntz
  3. **
  4. **  Translation into E by Klaus Becker
  5. **
  6. **  All comments are from the C-Source
  7. */
  8.  
  9. /*
  10. ** The Settings Demo shows how to load and save object contents.
  11. */
  12.  
  13. OPT PREPROCESS
  14.  
  15. MODULE 'tools/domethod'
  16. MODULE 'muimaster', 'libraries/mui'
  17. MODULE 'utility/tagitem', 'utility/hooks','tools/installhook'
  18. MODULE 'intuition/classes', 'intuition/classusr'
  19. MODULE 'libraries/gadtools'
  20.  
  21. ENUM ID_CANCEL=1,ID_SAVE,ID_USE
  22. ENUM ER_NONE, ER_MUILIB, ER_APP          /* for the exception handling */
  23.  
  24. DEF helpHook:hook
  25.  
  26. PROC helpFunc(hook,help,objptr:PTR TO LONG)
  27.   DEF udata=NIL
  28.   IF objptr[] THEN  get(objptr[]++,MUIA_UserData,{udata})
  29.   set(help,MUIA_Text_Contents,udata)
  30. ENDPROC
  31.  
  32. PROC main() HANDLE
  33.  
  34.   DEF app,window,str1,str2,str3,sl1,cy1,help,btsave,btuse,btcancel
  35.   DEF signals,result
  36.   DEF running=TRUE
  37.   DEF sex
  38.  
  39.   IF (muimasterbase := OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN))=NIL THEN Raise(ER_MUILIB)
  40.     
  41.   sex:=['male','female',NIL]
  42.  
  43.   installhook(helpHook,{helpFunc})
  44.  
  45.   app:= ApplicationObject,
  46.     MUIA_Application_Title      , 'Settings',
  47.     MUIA_Application_Version    , '$VER: Settings 10.12 (23.12.94)',
  48.     MUIA_Application_Copyright  , ' 1992/93, Stefan Stuntz',
  49.     MUIA_Application_Author     , 'Stefan Stuntz & Klaus Becker',
  50.     MUIA_Application_Description, 'Show saving AND loading of settings',
  51.     MUIA_Application_Base       , 'SETTINGS',
  52.     SubWindow, window:= WindowObject,
  53.       MUIA_Window_Title, 'Save/use me AND start me again!',
  54.       MUIA_Window_ID   , "SETT",
  55.       MUIA_Window_NeedsMouseObject, MUI_TRUE,
  56.         WindowContents, VGroup,
  57.           Child, ColGroup(2), GroupFrameT('User Identification'),
  58.             Child, Label2('Name:'),
  59.             Child, str1:= StringObject, StringFrame,
  60.               MUIA_ExportID, 1,
  61.               MUIA_UserData, 'First AND last name of user.',
  62.             End,
  63.             Child, Label2('Address:'),
  64.             Child, str2:= StringObject, StringFrame,
  65.               MUIA_ExportID, 2,
  66.               MUIA_UserData, 'Street, city AND ZIP code.' ,
  67.             End,
  68.             Child, Label1('Password:'),
  69.             Child, str3:= StringObject, StringFrame,
  70.               MUIA_ExportID, 4,
  71.               MUIA_UserData, 'Global access password (invisible).',
  72.               MUIA_String_Secret, MUI_TRUE,
  73.             End,
  74.             Child, Label1('Sex:'),
  75.             Child, cy1:= CycleObject,
  76.               MUIA_ExportID, 6,
  77.               MUIA_Cycle_Entries, sex,
  78.               MUIA_UserData, 'Guess what this means...',
  79.             End,
  80.             Child, Label('Age:'),
  81.             Child, sl1:= SliderObject,
  82.               MUIA_ExportID, 5,
  83.               MUIA_Slider_Min, 9,
  84.               MUIA_Slider_Max, 99,
  85.               MUIA_UserData, 'Several areas require a minimum age.',
  86.             End,
  87.             Child, Label1('Info:'),
  88.             Child, help:= TextObject, TextFrame,
  89.               MUIA_UserData, 'This is the info gadget.',
  90.             End,
  91.           End,
  92.           Child, VSpace(2),
  93.           Child, HGroup, MUIA_Group_SameSize, MUI_TRUE,
  94.             Child, btsave:= SimpleButton('_Save'),
  95.             Child, HSpace(0),
  96.             Child, btuse:= SimpleButton('_Use'),
  97.             Child, HSpace(0),
  98.             Child, btcancel:= SimpleButton('_Cancel'),
  99.          End,
  100.        End,
  101.      End,
  102.    End
  103.  
  104.  IF app=NIL THEN Raise(ER_APP)
  105.  
  106. /*
  107. ** Set Mouse Move Help Strings
  108. */
  109.  
  110.   doMethod(window,[MUIM_Notify,MUIA_Window_MouseObject,MUIV_EveryTime,
  111.     help,3,MUIM_CallHook,helpHook,MUIV_TriggerValue])
  112.  
  113.  
  114. /*
  115. ** Install notification events...
  116. */
  117.  
  118.   doMethod(window,[MUIM_Notify,MUIA_Window_CloseRequest,MUI_TRUE,
  119.                    app,2,MUIM_Application_ReturnID,ID_CANCEL])
  120.  
  121.   doMethod(btcancel,[MUIM_Notify,MUIA_Pressed,FALSE,
  122.                      app,2,MUIM_Application_ReturnID,ID_CANCEL])
  123.  
  124.   doMethod(btsave,[MUIM_Notify,MUIA_Pressed,FALSE,
  125.                    app,2,MUIM_Application_ReturnID,ID_SAVE])
  126.  
  127.   doMethod(btuse,[MUIM_Notify,MUIA_Pressed,FALSE,
  128.                   app,2,MUIM_Application_ReturnID,ID_USE])
  129.  
  130.  
  131. /*
  132. ** Cycle chain for keyboard control
  133. */
  134.  
  135.   doMethod(window,[MUIM_Window_SetCycleChain,
  136.                    str1,str2,str3,cy1,sl1,btsave,btuse,btcancel,NIL])
  137.  
  138.  
  139. /*
  140. ** Concatenate strings, <return> will activate the next one
  141. */
  142.  
  143.   doMethod(str1,[MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  144.     window,3,MUIM_Set,MUIA_Window_ActiveObject,str2])
  145.  
  146.   doMethod(str2,[MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  147.     window,3,MUIM_Set,MUIA_Window_ActiveObject,str3])
  148.  
  149.   doMethod(str3,[MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  150.     window,3,MUIM_Set,MUIA_Window_ActiveObject,str1])
  151.  
  152.  
  153. /*
  154. ** The application is set up, now load
  155. ** a previously saved configuration from env:
  156. */
  157.  
  158.   doMethod(app,[MUIM_Application_Load,MUIV_Application_Load_ENV])
  159.  
  160. /*
  161. ** Input loop...
  162. */
  163.  
  164.   set(window,MUIA_Window_Open,MUI_TRUE)
  165.   set(window,MUIA_Window_ActiveObject,str1)
  166.  
  167.   WHILE running
  168.  
  169.     result:=doMethod(app,[MUIM_Application_Input,{signals}])
  170.  
  171.     SELECT result
  172.  
  173.       CASE MUIV_Application_ReturnID_Quit
  174.            running:=FALSE
  175.       CASE ID_CANCEL
  176.            running:=FALSE
  177.  
  178.       CASE ID_SAVE
  179.         doMethod(app,[MUIM_Application_Save,MUIV_Application_Save_ENVARC])
  180.         doMethod(app,[MUIM_Application_Save,MUIV_Application_Save_ENV])
  181.         running:=FALSE
  182.       CASE ID_USE
  183.         doMethod(app,[MUIM_Application_Save,MUIV_Application_Save_ENV])
  184.         running:=FALSE
  185.     ENDSELECT
  186.  
  187.     IF (running OR signals) THEN Wait(signals)
  188.   ENDWHILE
  189.  
  190.   set(window,MUIA_Window_Open,FALSE)
  191.   Raise (ER_NONE)
  192.  
  193. EXCEPT
  194.   IF app THEN Mui_DisposeObject(app)
  195.   IF muimasterbase THEN CloseLibrary(muimasterbase)
  196.  
  197.   SELECT exception
  198.     CASE ER_MUILIB
  199.       WriteF('Failed to open \s.\n',MUIMASTER_NAME)
  200.       CleanUp(20)
  201.  
  202.     CASE ER_APP
  203.       WriteF('Failed to create application.\n')
  204.       CleanUp(20)
  205.  
  206.   ENDSELECT
  207.  
  208. ENDPROC 0
  209.